package com.tang.mq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception {
        //第二个参数开启消息追踪
        DefaultMQProducer producer = new DefaultMQProducer("producer_group",true);
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();
        for (int i = 0; i < 10; i++) {
            String info="message from rocketmq producer:"+i;
            Message msg = new Message("test-spmc-topic", "spmcTag", info.getBytes());
            //setKeys这个方法就是设置每个消息的MessageKey
            msg.setKeys("SPMC");
            producer.send(msg);
        }
        System.out.println("发送成功");
    }
}